package org.pblue.tumblarity.data.bean;

import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;

import org.pblue.appengine.AppengineDataException;
import org.pblue.appengine.AppengineDataManager;
import org.pblue.appengine.DataBean;

@PersistenceCapable(identityType=IdentityType.APPLICATION, detachable="true")
public class Follower extends DataBean {

  private static final long serialVersionUID = 8976528406588576354L;
  
  @Persistent
  private String name;
  
  @Persistent
  private String url;
  
  @Persistent
  private String thumbnail; 
  
  @Persistent
  private String tumblelogId;
  
  @Persistent
  private int page;
  
  public Follower(String pName, String pUrl, String pThumbnail, Tumblelog pTumblelog, int pPage) {
    super(generateId(pName, pTumblelog.getId()), pTumblelog);

    this.setName(pName);
    this.setUrl(pUrl);
    this.setThumbnail(pThumbnail);
    this.setTumblelogId(pTumblelog.getId());
    this.setPage(pPage);
  }
  
  public static String generateId(String pName, String pTumblelogId) {
    return pName + pTumblelogId;
  }
  
  public boolean equals(Object pFollower) {
    if (pFollower instanceof Follower) {
      Follower follower = (Follower) pFollower;
      return follower.getName().equals(this.getName());
    }
    return false;
  }
  
  public int hashCode() {
    return getName().hashCode();
  }
  
  public static Follower get(String pId, Tumblelog pTumblelog) throws AppengineDataException {
    return (Follower) DataBean.get(Follower.class, pId, pTumblelog);
  }
  
  public static Follower get(String pId, Tumblelog pTumblelog, AppengineDataManager pDataManager) throws AppengineDataException {
    return (Follower) DataBean.get(Follower.class, pId, pTumblelog, pDataManager);
  }
  
  public String getName() {
    return name;
  }
  
  public void setName(String pName) {
    name = pName;
  }
  
  public String getUrl() {
    return url;
  }
  
  public void setUrl(String pUrl) {
    url = pUrl;
  }

  public String getThumbnail() {
    return thumbnail;
  }
  
  public void setThumbnail(String pThumbnail) {
    thumbnail = pThumbnail;
  }

  
  public String getTumblelogId() {
    return tumblelogId;
  }
  
  public void setTumblelogId(String pTumblelogId) {
    tumblelogId = pTumblelogId;
  }
  
  public int getPage() {
    return page;
  }
  
  public void setPage(int pPage) {
    page = pPage;
  }

}